#ifndef __DEBUG_H_INCLUDED__
#define __DEBUG_H_INCLUDED__

#include <iostream>
#include <fstream>

class DBG{
public:
	std::ofstream stream;
	bool echo;
public:
	DBG(){
		stream.exceptions(std::ios_base::goodbit);
	}
	
	void setArchivo(const char* nombre){
		stream.close();
		stream.open(nombre,std::ios_base::out|std::ios_base::trunc);
	}
	
	void setEcho(bool state){
		echo = state;
	}
	
	std::ostream& operator<<(std::ostream &s){
		if(echo)
			std::cout << s;
		return stream << s<< std::flush;
	}
	
	std::ostream& operator<<(std::string &s){
		if(echo)
			std::cout << s;
		return stream << s<< std::flush;
	}

	std::ostream& operator<<(int i){
		if(echo)
			std::cout << i;
		return stream << i << std::flush;
	}


	std::ostream& operator<<(const char* s){
		if(echo)
			std::cout << s;
		return stream << s << std::flush ;
	}

};
namespace std{
	extern DBG dbg;
}
#endif //__DEBUG_H_INCLUDED__
